﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Topology;

using DotSpatial.Symbology;

using System.Drawing;

using System.Drawing.Drawing2D;

using Point = DotSpatial.Topology.Point;

using System.ComponentModel;




namespace FXnaGis
{
    [Serializable]
   public class FPointShape:FShape
    {

        public FPointShape(string id)
            : base(id)
        {
            this._point = new Point();
        }

       

       public FPointShape(string id, Coordinate c):base(id)
       {
           this._point = new Point((Coordinate)c.Clone ());
        

         
 
       }


       Point _point;

        [Browsable(false)]
       public Point Point
       {
           get { return _point; }
           set { 
               
               _point = value;

              
           
           }
       }



        [DisplayName("X坐标")]
        public double XCoord
        {
            get { return this._point.Coordinate.X; }
            set { this._point.Coordinate.X = value;

            this.OnResetCoord();
            }
          
        }


        [DisplayName("Y坐标")]
        public double YCoord
        {
            get { return this._point.Coordinate.Y; }
            set { this._point.Coordinate.Y = value;

            this.OnResetCoord();
            
            }

        }

        [DisplayName("Z坐标")]
        public double ZCoord
        {
            get { return this._point.Coordinate.Z; }
            set { this._point.Coordinate.Z = value;

            this.OnResetCoord();
            }

        }


        void OnResetCoord()
        {
            this._point.UpdateEnvelope();

            this.Parent.AskRefresh();
 
        }







       public override void Draw(FMapArgs args)
       {
           PointStyle ptStyle = this.Parent.PointStyle;

         

           


           System.Drawing.Point pt = args.ProjToPixel(this.Point.Coordinate);

           

           Matrix origTransform = args.Device.Transform;

           Matrix shift = origTransform.Clone();
           shift.Translate(pt.X, pt.Y);



           args.Device.Transform = shift;



           ptStyle.Draw(args.Device, 1);




           args.Device.Transform = origTransform;

          
       }
       public override void DrawLable(FMapArgs args)
       {
           base.DrawLable(args);

           LableStyle ls = this.Parent.LableStyle;

           System.Drawing.Point pt =args.ProjToPixel( this._point.Coordinate);

           ls.DrawString(args.Device,this.Desc, pt);




       }



       public override void Move(double xOffset, double yOffset, double zOffset)
       {
           this.Point.X = this.Point.X + xOffset;

           this.Point.Y = this.Point.Y + yOffset;

           this.Point.UpdateEnvelope();


       }


       public override bool Intersects(Envelope envelope)
       {
           return this._point.Intersects(envelope);

       }


       public override DotSpatial.Data.Extent Extent
       {
           get
           {
               return new DotSpatial.Data.Extent(this._point.Envelope);
           }
       }

    





    }
}
